<?php #//v.3.3.0
#///////////////////////////////////////////////////////
#//  COPYRIGHT 2004 Phpauction.org ALL RIGHTS RESERVED//
#///////////////////////////////////////////////////////


include "./includes/config.inc.php";

#///////////////////////////////////////////////////////
#//  Categories Creation List & Select                 //
#///////////////////////////////////////////////////////


if($SETTINGS['catsorting'] == 'alpha') {
	$catsorting = " ORDER BY t.cat_name ASC";
} else {
	$catsorting = " ORDER BY sub_counter DESC";
}  

$TPL_categories_select = "

<SCRIPT LANGUAGE=JavaScript>

<!--
function openURL()
{

      // grab index number of the selected option
      selInd = document.categorypulldown.category.selectedIndex;

      // get value of the selected option
      goURL = document.categorypulldown.category.options[selInd].value;

      // redirect browser to the grabbed value (here a URL)
      top.location.href = goURL;

}

//-->
</SCRIPT>

           <form name=categorypulldown>
<SELECT NAME=category onChange=openURL(this.form)
SIZE=1 CLASS=categories_select_puldown_class id=categories_select_puldown_id >
<OPTION SELECTED VALUE=0> Choose Category</OPTION>
   
"; 



$TPL_categories_value = ""; 
$query = "select distinct c.cat_id,t.cat_name, c.sub_counter, c.cat_colour,c.cat_image, c.counter from PHPAUCTIONXL_categories c, PHPAUCTIONXL_cats_translated t 
          WHERE c.parent_id=0
          AND t.cat_id=c.cat_id
          AND t.lang='".$language."'
          $catsorting";
$result = mysql_query($query);
if(!$result) {
	MySQLError($query);
	exit;
	
	
} else {
	$num_cat = mysql_num_rows($result);
	$i = 0;
	$TPL_categories_value = "<ul CLASS=categories_list_class id=categories_list_id >\n";
	
  
  while($i < $num_cat && $i < $SETTINGS['catstoshow']) {
		$catlink="";
		$cat_id = mysql_result($result,$i,"cat_id");
		$cat_name = mysql_result($result,$i,"cat_name");
		$sub_count = intval(mysql_result($result, $i, "sub_counter"));
		$cat_colour = mysql_result($result, $i, "cat_colour");
		$cat_image = mysql_result($result, $i, "cat_image");
		$cat_counter = (int)mysql_result($result, $i, "counter" );
		if ($sub_count!=0)
			$cat_counter = "(".$sub_count.")";
		else {
			$cat_counter = "";
		}
		$cat_url = "./browse.php?id=$cat_id";  
		if ( $cat_image != "") {
			$catlink = "<A HREF=\"$cat_url\"><IMG SRC=\"$cat_image\" BORDER=0></a>";
		}
		$catlink .= "<A HREF=\"$cat_url\">$cat_name</A>"." $cat_counter";
		if ( $cat_colour != "") {
			$catlink = setsspan($catlink,"background-color:$cat_colour");
		}
		$TPL_categories_value .= "<li>".$catlink."</li>\n";
		
		$TPL_categories_select .= "<OPTION VALUE=$cat_url>$cat_name</OPTION>\n"; 
		
		
		
		
		$i++;
	}
	$TPL_categories_value .= "</ul>\n";
	 $TPL_categories_select .= "</SELECT></FORM>"; 
	
        $categories_list = $TPL_categories_value;
        $categories_select = $TPL_categories_select;

//echo $categories_list;  

//echo $categories_select;

}


?>
